home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / areuh.tar / areuh / linker / llist.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  4KB  |  168 lines

  1. /*
  2.  * Authors :
  3.  *   Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet)
  4.  *   Janick TAILLANDIER
  5.  *
  6.  * This program can be freely used or distributed as long as this
  7.  * note is kept.
  8.  *
  9.  * This program is provided "as is".
  10.  */
  11.  
  12. #include "lglobal.h"
  13.  
  14. FILE *fd_l ;
  15. int l_line = 0, l_page = 1 ;
  16.  
  17. void l_files (), l_xref () ;
  18.  
  19.  
  20.  
  21. void l_init ()
  22. {
  23.     uchar dfl [MAXLEN+1] ;
  24.  
  25.     switch (cntlist)
  26.     {
  27.         case 0 :
  28.             break ;
  29.         case 1 :
  30.             fd_l = stdout ;
  31.             strcpy (flisting, "stdout") ;
  32.             break ;
  33.         case 2 :
  34.             dfl_extension (dfl, "list", "al") ;
  35.             look_obj (flisting, dfl) ;
  36.             if (!(fd_l = fopen (flisting, "w")))
  37.                 error (ERROPN, flisting) ;
  38.             break ;
  39.     }
  40. }
  41.  
  42.  
  43. void l_new_page (flag)
  44. int flag ;
  45. {
  46.     if (!cntlist) return ;
  47.     for (; l_line<page_size; l_line++) fprintf (fd_l, "\n") ;
  48.     if (flag)
  49.     {
  50.         fprintf (fd_l,"AREUH LINKER V2.2 - Page %03d - File: %s\n",
  51.                       ++l_page, flex) ;
  52.         fprintf (fd_l,"\n") ;
  53.         l_line = 2 ;
  54.     }
  55.     if (ferror (fd_l)) error (ERRWRT, flisting) ;
  56. }
  57.  
  58.  
  59. void l_flush ()
  60. {
  61.     if (!cntlist) return ;
  62.     l_new_page (0) ;
  63.     if (cntlist==2)
  64.         if (fclose (fd_l)) error (ERRCLO, flisting) ;
  65. }
  66.  
  67.  
  68. void l_print (line)
  69. uchar *line ;
  70. {
  71.     if (!cntlist)
  72.     {
  73.         printf ("%s\n", line) ;
  74.         return ;
  75.     }
  76.  
  77.     if (l_line==page_size-6) l_new_page (1) ;
  78.     fprintf (fd_l, "%s\n", line) ;
  79.     l_line++ ;
  80.     if (ferror (fd_l)) error (ERRWRT, flisting) ;
  81. }
  82.  
  83.  
  84. void report ()
  85. {
  86.     if (cntlist && errnb) l_new_page (1) ;
  87.     if (xref) l_xref () ;
  88.     if (cntlist && xref) l_new_page (1) ;
  89.     if (cntlist) l_files () ;
  90.     else if (xref && errnb)
  91.     {
  92.         printf ("Areuh linker : %03d errors", errnb) ;
  93.         if (ferror (fd_l)) error (ERRWRT, flisting) ;
  94.     }
  95. }
  96.  
  97.  
  98. void l_files ()
  99. {
  100.     uchar line[MAXLEN+1], start[MAXLEN+1], end[MAXLEN+1], length[MAXLEN+1] ;
  101.     int i ;
  102.     saddr val ;
  103.  
  104.     sprintf (line, "Output module : %s", flex) ;
  105.     l_print (line) ;
  106.     l_print ("") ;
  107.     for (file=1; file<=nfile; file++)
  108.     {
  109.         sprintf (line, "Source module : %s", fname [file]) ;
  110.         l_print (line) ;
  111.         hex5 (start, tmodule[file].m_ad) ;
  112.         val = (tmodule[file].m_ad==tmodule[file+1].m_ad) ? 0 : 1 ;
  113.         hex5 (end, tmodule[file+1].m_ad - val) ;
  114.         hex5 (length, tmodule[file+1].m_ad - tmodule[file].m_ad) ;
  115.         sprintf (line, "%10sStart = %s, End = %s, Length = %s", 
  116.                        "", start, end, length) ;
  117.         l_print (line) ;
  118.         l_print ("") ;
  119.     }
  120.     for (i=0; i<4; i++) l_print ("") ;
  121.     strcpy (line, "Date : ") ;
  122.     format_time (line+7) ;
  123.     l_print (line) ;
  124.     l_print ("") ;
  125.     sprintf (line, "Errors : %03d", errnb) ;
  126.     l_print (line) ;
  127.     l_print ("") ;
  128.     l_print ("") ;
  129.     l_print ("Areuh Assembler/Linker V2.2, (c) P. David & J. Taillandier 1986  Paris, France") ;
  130.     l_new_page (0) ;
  131. }
  132.  
  133.  
  134. void l_xref ()
  135. {
  136.     uchar line [MAXLEN+1], tmp [MAXLEN+1], rel [MAXLEN+1] ;
  137.     uchar format [MAXLEN+1], xformat [MAXLEN+1] ;
  138.     struct symbol *t ;
  139.     struct xtable *x ;
  140.     int i ;
  141.  
  142.     sprintf (format, "%%-%ds = %%s  File : %%s", LBLLEN+1) ;
  143.     sprintf (xformat, "%%%ds+ %%s   (Rel %%s in %%s)", LBLLEN+11) ;
  144.     for (i=0; i<=255; i++)
  145.     {
  146.         t = h_label [i]->s_next ;
  147.         while (t)
  148.         {
  149.             if (!t->s_os)
  150.             {
  151.                 hex5 (tmp, t->s_value) ;
  152.                 sprintf (line, format, t->s_name, tmp, fname[t->s_file]) ;
  153.                 l_print (line) ;
  154.                 x = t->s_xref ;
  155.                 while (x)
  156.                 {
  157.                     hex5 (tmp, tmodule[x->x_file].m_ad + x->x_pc) ;
  158.                     hex5 (rel, x->x_pc) ;
  159.                     sprintf (line, xformat, "", tmp, rel, fname[x->x_file]) ;
  160.                     l_print (line) ;
  161.                     x = x->x_next ;
  162.                 }
  163.             } /* du if */
  164.             t = t->s_next ;
  165.         } /* du while */
  166.     } /* du for */
  167. }
  168.